package com.fyf.game.net;

import java.nio.ByteBuffer;
import org.je.io.IOUtil;
import org.je.util.NumberUtil;

/**
 * @author fanyifeng 2013-1-8
 */
public class GameProtocol
{
	public static final byte[]	PTC_PREFIX	= "mm@fyf".getBytes();

	/**
	 * @param msg
	 * @return bytebuffer
	 */
	public static ByteBuffer wrap(String msg) {
		byte[] b = IOUtil.utf8(msg);
		byte[] arr = new byte[b.length + 10];
		System.arraycopy(PTC_PREFIX, 0, arr, 0, 6);
		System.arraycopy(NumberUtil.int2bytes(arr.length), 0, arr, 6, 4);
		if (b.length > 0)
			System.arraycopy(b, 0, arr, 10, b.length);
		return ByteBuffer.wrap(arr);
	}
}
